﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;

using System.Net;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;

namespace Web
{
    public partial class lichthidau : System.Web.UI.Page
    {
        string strHtml = string.Empty; 
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                GetliveEPL();                
            }
            catch (Exception)
            {             
            }
        }

        void GetliveEPL()
        {
            StreamReader StreamHandler;
            XmlDocument xmlDoc = new XmlDocument();

            string strURL = "http://odds.fun88.com/";

            HttpWebRequest wRequest = (HttpWebRequest)WebRequest.Create(strURL);
            wRequest.Headers.Add("Man", "GET " + strURL);
            HttpWebResponse wResponse = (HttpWebResponse)wRequest.GetResponse();
            if (wRequest.HaveResponse)
            {
                if (wResponse.StatusCode == HttpStatusCode.OK)
                {
                    StreamHandler = new System.IO.StreamReader(wResponse.GetResponseStream());
                    xmlDoc.LoadXml(StreamHandler.ReadToEnd());
                }
            }                     
            XmlNodeList list = xmlDoc.SelectNodes("//match[@ge='*ENGLISH PREMIER LEAGUE']");
            int count = 0;

            strHtml += "<tr style=\"background:#ddd;color:#000;font-weight:bold;\">";
            strHtml += "<td width=\"70%\" rowspan=\"2\" colspan=\"2\">English Premier League</td>";
            strHtml += "<td align=\"center\" colspan=\"3\" >Tỷ lệ</td>";
            strHtml += "<td align=\"center\" colspan=\"3\" style=\"display:none;\">Tỷ lệ Châu Âu</td>";
            strHtml += "</tr>";

            strHtml += "<tr style=\"background:#ddd;color:#000;font-weight:bold;\">";
            strHtml += "<td align=\"center\">Chủ</td>";
            strHtml += "<td align=\"center\">Chấp</td>";
            strHtml += "<td align=\"center\">Khách</td>";
            strHtml += "<td align=\"center\" style=\"display:none;\">Chủ</td>";
            strHtml += "<td align=\"center\" style=\"display:none;\">Hòa</td>";
            strHtml += "<td align=\"center\" style=\"display:none;\">Khách</td>";
            strHtml += "</tr>";

            foreach (XmlNode item in list)
            {
                if (count < 40)
                {
                    try
                    {
                        strHtml += "<tr style=\"height:30px;\">";
                        DateTime ngayThiDau = new DateTime();
                        try
                        {
                            CultureInfo provider = CultureInfo.InvariantCulture;
                            //ngayThiDau = DateTime.ParseExact(item.Attributes["mt"].Value, "M/d/yyyy h:mm:ss tt", provider);
                            ngayThiDau = DateTime.ParseExact(item.Attributes["mt"].Value, "M/d/yyyy h:mm:ss tt", provider);
                            strHtml += "<td align=\"center\">" + ngayThiDau + "</td>";
                        }
                        catch { }
                        strHtml += "<td><b>" + item.Attributes["he"].Value + "</b> vs " + item.Attributes["ae"].Value + "</td>";
                        xmlDoc.LoadXml(item.InnerXml);
                        XmlNodeList listTLCA = xmlDoc.SelectNodes("//odd[@t='ah']");
                        foreach (XmlNode tlca in listTLCA)
                        {
                            strHtml += "<td align=\"center\" style=\"background:#EFEFEF\">" + tlca.Attributes["h"].Value + "</b></td>";
                            strHtml += "<td align=\"center\" style=\"background:#EFEFEF\"><b>" + tlca.Attributes["o"].Value + "</b></td>";
                            strHtml += "<td align=\"center\" style=\"background:#EFEFEF\"><b>" + tlca.Attributes["u"].Value + "</b></td>";                                                        
                            break;
                        }
                        strHtml += "<td nowrap=\"\" align=\"center\" style=\"display:none;\"><b>0</b></td>";
                        strHtml += "<td nowrap=\"\" align=\"center\" style=\"display:none;\">0</td>";
                        strHtml += "<td nowrap=\"\" align=\"center\" style=\"display:none;\">0</td>";
                        strHtml += "</tr>";
                    }
                    catch { }
                    count++;
                }
            }
         
            ltdata.Text = strHtml;

        }

        

        void Getlive1()
        {          
            StreamReader StreamHandler;
            XmlDocument xmlDoc = new XmlDocument();

            string strURL = "http://odds.fun88.com/";

            HttpWebRequest wRequest = (HttpWebRequest)WebRequest.Create(strURL);
            wRequest.Headers.Add("Man", "GET " + strURL);
            HttpWebResponse wResponse = (HttpWebResponse)wRequest.GetResponse();
            if (wRequest.HaveResponse)
            {
                if (wResponse.StatusCode == HttpStatusCode.OK)
                {
                    StreamHandler = new System.IO.StreamReader(wResponse.GetResponseStream());
                    xmlDoc.LoadXml(StreamHandler.ReadToEnd());
                }
            }

            string strHtml = string.Empty;
            string Info = string.Empty;
            XmlNodeList list = xmlDoc.SelectNodes("//match[@ge='*ENGLISH PREMIER LEAGUE']");
            int count = 0;
            strHtml = "<table width=\"100%\" border=\"1\">";
            strHtml += "<tr><td>doi nha</td><td>doi khach</td><td>Ngay thi dau</td><td>Gio thi dau</td><td>Ma tran dau</td><td>TLCA_Catran</td><td>TLCA_Chu</td><td>TLCA_Khach</td>";
            strHtml += "</tr>";
            foreach (XmlNode item in list)
            {
                if (count < 40)
                {
                    try
                    {
                        strHtml +=
                            "<tr><td>" + item.Attributes["he"].Value + "</td><td>" + item.Attributes["ae"].Value + "</td>";
                        //lich.DoiNha = item.Attributes["he"].Value;
                        //lich.DoiKhach = item.Attributes["ae"].Value;
                        DateTime ngayThiDau = new DateTime();
                        try
                        {
                            CultureInfo provider = CultureInfo.InvariantCulture;
                            ngayThiDau = DateTime.ParseExact(item.Attributes["mt"].Value, "M/d/yyyy h:mm:ss tt", provider);
                            //lich.NgayThiDau = ngayThiDau;
                            strHtml +=
                                "<td>" + ngayThiDau + "</td>";
                        }
                        catch { }
                        //lich.GioThiDau = lich.NgayThiDau.AddHours(-1).ToString("HH:mm:ss");
                        //lich.MaTranDau = int.Parse(item.Attributes["id"].Value);

                        strHtml +=
                                "<td>" + ngayThiDau.AddHours(-1).ToString("HH:mm:ss") + "</td><td>" + item.Attributes["id"].Value + "</td>";


                        xmlDoc.LoadXml(item.InnerXml);
                        XmlNodeList listTLCA = xmlDoc.SelectNodes("//odd[@t='ah']");
                        foreach (XmlNode tlca in listTLCA)
                        {
                            strHtml += "<td>" + tlca.Attributes["h"].Value + "</td><td>" + tlca.Attributes["o"].Value + "</td><td>" + tlca.Attributes["u"].Value + "</td>";
                            //lich.TLCA_Catran = tlca.Attributes["h"].Value;
                            //lich.TLCA_Chu = tlca.Attributes["o"].Value;
                            //lich.TLCA_Khach = tlca.Attributes["u"].Value;
                            break;
                        }

                        //XmlNodeList listTLBT = xmlDoc.SelectNodes("//odd[@t='ou']");
                        //foreach (XmlNode tlca in listTLBT)
                        //{
                        //    lich.TLBT_Catran = tlca.Attributes["h"].Value;
                        //    lich.TLBT_Tren = tlca.Attributes["o"].Value;
                        //    lich.TLBT_Duoi = tlca.Attributes["u"].Value;
                        //    break;
                        //}
                        strHtml += "</tr>";
                    }
                    catch { }
                    count++;
                }
            }
            strHtml += "</table>";
            ltdata.Text = strHtml;
            
        }
    }
}